﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CopyPhpFile {
    public partial class Form1 : Form {

        string[] fileNames;
        string currentPathDirectory = "";

        public Form1 () {
            fileNames = new string[]{
                "crypto-trade.com.php",
                "poloniex.com.php",
                "cryptsy.com.php"
            };

            InitializeComponent();
            this.Visible = false;
        }

        private void Form1_Load ( object sender, EventArgs e ) {
            string [] drives;
            bool found_xampp = false;
            drives = Environment.GetLogicalDrives();
            string root_path = string.Empty;
            for ( int i = 0; i < drives.Length; i++ ) {
                root_path = drives[i] + "xampp\\";
                if ( Directory.Exists( root_path ) ) {
                    found_xampp = true;
                    break;

                }
            }

            currentPathDirectory = Directory.GetCurrentDirectory();
            string pathPhpFile = currentPathDirectory.Replace("CopyPhpFile\\bin\\Debug", "php\\");

            //string[] argv = Environment.GetCommandLineArgs();
            //if (argv.Length > 1)
            //{
            //    filename = Path.GetFileName(argv[1]);
            //    path = Path.GetDirectoryName(argv[1]);

            //}

            if ( !found_xampp ) {
                MessageBox.Show( "Please install XAMPP. \nThis application will close", "Error" );
                Environment.Exit( 1 );

            } else {
                if ( !Directory.Exists( root_path + "htdocs\\nanobot" ) ) {
                    Directory.CreateDirectory( root_path + "htdocs\\nanobot" );

                }

                try {
                    foreach ( var item in fileNames ) {

                        File.Copy(Path.Combine(pathPhpFile, item), root_path + "htdocs\\nanobot\\" + item, true);
                        //File.Copy( "crypto-trade.com.php", "C:\\crypto-trade.com.php", true );
                    }
                } catch ( IOException ioex ) {

                    //MessageBox.Show( "Coudn\'t find crypto-trade.com.php", "File Missing" );
                    MessageBox.Show( ioex.Message, "Error Copying File(s)" );
                    Environment.Exit( 1 );

                } catch ( Exception ex ) {
                    MessageBox.Show( ex.Message, "Error" );

                    Environment.Exit( 1 );

                }



            }
            this.Close();

            Environment.Exit( Environment.ExitCode );





        }


    }
}
